<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS中获取元素的三种方式</title>
</head>

<body>
    <div id="div1"></div>

    <input type="checkbox" name="aihao" value="1">
    <input type="checkbox" name="aihao" value="2">
    <input type="checkbox" name="aihao" value="3">
    <input type="checkbox" name="aihao" value="4">

    <script>
        // 这是JS中非常经典的获取元素的三种方式
        // 根据id获取一个元素
        var div1 = document.getElementById("div1")
        console.log(div1)

        // 根据name属性获取多个元素
        var aihaos = document.getElementsByName("aihao")
        console.log(aihaos)

        // 根据标签的名字获取
        var divs = document.getElementsByTagName("div")
        console.log(divs)
    </script>
</body>

</html>